package com.szyibei.system.common.vo;

import lombok.Data;

/**
 * 类名: CommonResult
 * 包名：  com.alipayeco.medicalinscore.share.result
 * 作者：  Guanfm
 * 时间：  2017年5月26日 上午10:09:35
 * 描述: 通用返回结果类
 * @since 1.0.0
 *
 * 修改历史 :
 * 1. [2017年5月26日]新建类 by Guanfm
 *
 * @param <T>
 */
@Data
public class CommonResult<T> extends Result {

    private T content;
    
    private String code;
    
    private String message;
    
    private String resultCode;

    public String getResultCode() {
        return resultCode;
    }

    public void setResultCode(String resultCode) {
        this.resultCode = resultCode;
    }

    public CommonResult<T> success() {
    	this.code = "S";
        this.success = true;
        return this;
    }

    public CommonResult<T> fail() {
    	this.code="F";
        this.success = false;
        return this;
    }

    public CommonResult<T> content(T content) {
        this.content = content;
        return this;
    }

    public CommonResult<T> displayMessage(String displayMessage) {
        this.displayMessage = displayMessage;
        return this;
    }

    public CommonResult<T> errorCode(String errorCode) {
        this.errorCode = errorCode;
        return this;
    }

    public CommonResult<T> errorDesc(String errorDesc) {
        this.errorDesc = errorDesc;
        this.message = errorDesc;
        return this;
    }

    public T getContent() {
        return content;
    }

    public void setContent(T content) {
        this.content = content;
    }
    
    public static <T> CommonResult<T> ok(T content){
    	CommonResult<T> result = new CommonResult<T>();
    	result.setSuccess(true);
    	result.setCode("S");
    	result.setContent(content);
    	return result;
    }
    
    public static <T> CommonResult<T> fail(Exception e){
    	CommonResult<T> result = new CommonResult<T>();
    	result.setSuccess(false);
    	result.setCode("F");
    	result.setErrorDesc(e.getMessage());
    	return result;
    }

	public CommonResult<T> errorSource(String errorSource) {
        this.errorSource = errorSource;
        return this;
    }
}
